﻿<%@ Page Title="<%$Resources:Language,CmsVouchersTitle %>" Language="C#" MasterPageFile="~/cms.master"
    AutoEventWireup="true" CodeFile="Vouchers.aspx.cs" Inherits="cms_Vouchers" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Src="~/controls/ctrlWait.ascx" TagName="ctrlWait" TagPrefix="ctrl" %>
<%@ Register Src="~/controls/ctrlPager.ascx" TagName="ctrlPager" TagPrefix="ctrl" %>
<%@ Register Src="~/controls/ctrlShowInfo.ascx" TagName="ctrlShowInfo" TagPrefix="ctrl" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphMain" runat="Server">

    <script type="text/javascript">
        function printV(which) {
            selectedIDs = '';
            re1 = new RegExp(which);

            for (i = 0; i < document.forms[0].elements.length; i++) {
                elm = document.forms[0].elements[i];
                if (elm.type == 'checkbox' && re1.test(elm.name))
                    if (elm.checked == true) {
                    tab = elm.id.split('_');
                    selectedIDs += tab[1] + ',';
                }
            }
            if (selectedIDs != '') {
                window.open('ReportView.ashx?ReportType=Vouchers&IDs=' + selectedIDs);
            }


        }
        function SetAll(sender, which) {
            re1 = new RegExp(which);
            for (i = 0; i < document.forms[0].elements.length; i++) {
                elm = document.forms[0].elements[i];
                if (elm.type == 'checkbox') {
                    if (/*which==1 &&*/re1.test(elm.name))
                        elm.checked = sender.checked;
                    // if (which==0 && re2.test(elm.name))
                    //   elm.checked = sender.checked;
                }

            }
        }
    </script>

    <h2 id="H1" runat="server">
        <%=Resources.Language.Vouchers %></h2>
    <ctrl:ctrlWait ID="ctrlWait" runat="server" />
    <asp:UpdatePanel ID="upVouchers" runat="server">
        <ContentTemplate>
            <cc1:TabContainer ID="tcMenu" runat="server">
                <cc1:TabPanel runat="server" ID="tabGenerateVouchers" HeaderText="<%$Resources:Language,VouchersGenerate %>">
                    <ContentTemplate>
                        <ctrl:ctrlShowInfo ID="CtrlShowInfo" runat="server" />
                        <asp:Panel ID="pnlVouchers" runat="server">
                            <span class="peBoxLeft">
                                <%=Resources.Language.VoucherType %>:</span>
                            <asp:DropDownList ID="ddlVoucherType" runat="server" CssClass="DropDown">
                            </asp:DropDownList>
                            <br />
                            <span class="peBoxLeft">
                                <%=Resources.Language.Value %>:</span>
                            <asp:TextBox CssClass="TextInput" runat="server" ID="tbVoucherValue"></asp:TextBox><br />
                            <span class="peBoxLeft">
                                <%=Resources.Language.MinVoucherValue %>:</span>
                            <asp:TextBox CssClass="TextInput" runat="server" ID="tbVoucherMinVal"></asp:TextBox><br />
                            <span class="peBoxLeft">
                                <%=Resources.Language.Amount %>:</span>
                            <asp:TextBox CssClass="TextInput" runat="server" ID="tbAmount"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rqvAmount" ControlToValidate="tbAmount" Text="*"
                                Display="Dynamic" runat="server"></asp:RequiredFieldValidator>
                            <asp:CompareValidator ID="cmpAmount" ControlToValidate="tbAmount" Display="Dynamic" 
                                Type="Integer" runat="server" Operator="DataTypeCheck" Text="<%$Resources:Language,GiveNumber%>">
                            </asp:CompareValidator>
                            <br />
                            <div class="vSeparate">
                                <span class="peBoxLeft">&nbsp; </span>
                                <asp:Button ID="btnGenerate" runat="server" Text="<%$Resources:Language,GenerateVouchers %>"
                                    OnClick="btnGenerate_Click" />&nbsp;
                                <input type="button" value='<%=Resources.Language.PrintVouchers %>' onclick="printV('cbG')" />
                            </div>
                        </asp:Panel>
                        <br />
                        <asp:GridView ID="gvLastGenerated" runat="server" CssClass="cmsTables" AutoGenerateColumns="false"
                            EnableViewState="False" OnRowCreated="gv_RowCreated">
                            <Columns>
                                <asp:BoundField HeaderText="ID" DataField="IdVoucher" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,VoucherCode %>" DataField="Code" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,Date %>" DataField="Date" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,VoucherValue %>" DataField="Value" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,MinVoucherValue %>" DataField="AcceptValue" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,VoucherType %>" DataField="TypeString" />
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <input type="checkbox" id='cbG_<%#Eval("IdVoucher") %>' name="cbG" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <PagerSettings Mode="NumericFirstLast" Visible="false" />
                        </asp:GridView>
                    </ContentTemplate>
                </cc1:TabPanel>
                <cc1:TabPanel runat="server" ID="tabUnusedVouchers" HeaderText="<%$Resources:Language,UnusedVouchers %>">
                    <ContentTemplate>
                        <input type="button" value='<%=Resources.Language.PrintVouchers %>' onclick="printV('cbU')" />
                        <asp:GridView ID="gvUnused" runat="server" CssClass="cmsTables" AutoGenerateColumns="false"
                            AllowPaging="True" PageSize="50" EnableViewState="False" OnRowCreated="gv_RowCreated">
                            <Columns>
                                <asp:BoundField HeaderText="ID" DataField="IdVoucher" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,VoucherCode %>" DataField="Code" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,Date %>" DataField="Date" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,VoucherValue %>" DataField="Value" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,MinVoucherValue %>" DataField="AcceptValue" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,VoucherType %>" DataField="TypeString" />
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <input type="checkbox" id='cbU_<%#Eval("IdVoucher") %>' name="cbU" />
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <PagerSettings Mode="NumericFirstLast" Visible="false" />
                        </asp:GridView>
                        <ctrl:ctrlPager ID="ctrlPagerUn" runat="server" OnPageIndexChanged="ctrlPager_PageIndexChanged" />
                    </ContentTemplate>
                </cc1:TabPanel>
                <cc1:TabPanel runat="server" ID="tabUsedVouchers" HeaderText="<%$Resources:Language,UsedVouchers %>">
                    <ContentTemplate>
                        <asp:GridView ID="gvUsed" runat="server" CssClass="cmsTables" AutoGenerateColumns="false"
                            AllowPaging="True" PageSize="50" EnableViewState="False">
                            <Columns>
                                <asp:BoundField HeaderText="ID" DataField="IdVoucher" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,VoucherCode %>" DataField="Code" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,Date %>" DataField="Date" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,VoucherValue %>" DataField="Value" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,MinVoucherValue %>" DataField="AcceptValue" />
                                <asp:BoundField HeaderText="<%$ Resources:Language,VoucherType %>" DataField="TypeString" />
                                <asp:TemplateField HeaderText="<%$ Resources:Language,Order %>">
                                    <ItemTemplate>
                                        <a href='OrderEdit.aspx?RealizationID=<%#Eval("UsedRealizationId")%>'>
                                            <%=Resources.Language.Order %>:
                                            <%#Eval("UsedRealizationId")%></a>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <PagerSettings Mode="NumericFirstLast" Visible="false" />
                        </asp:GridView>
                        <ctrl:ctrlPager ID="ctrlPagerU" runat="server" OnPageIndexChanged="ctrlPager_PageIndexChanged" />
                    </ContentTemplate>
                </cc1:TabPanel>
            </cc1:TabContainer>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
